const YoloDetector = require('../yolo');
const APP = require('../APP');
class index{
    androidBot = null;
    done = false;
    constructor(client){
        this.GameClient = client;
        this.androidBot = this.GameClient.androidBot;
    }
    // 系统弹窗 - 单按钮
    async pop_sys_oneBtn(yoloData){
        let pop = APP.findClass(yoloData, 'pop');
    }
    // 弹窗 - 无关闭 - 有文字按钮
    async checkPop_1(){
        let data = await YoloDetector.screen(this.androidBot);
        let pop = APP.findClass(data, 'pop');
        let popContent =await APP.ocrRegion(this.androidBot,data[pop-1].region);
        if(popContent){
            if(APP.ocrDataFindTextArray(popContent,['提示','授权','失败','确定'])){
                // 授权失败弹窗
                await APP.clickRegion(this.androidBot,[405, 318, 555, 368]);
                this.done = true;
                return true;
            }
        }
    }
    async run(){
        // let words = await APP.ocrRegion(this.androidBot);
        let data = await YoloDetector.screen(this.androidBot);
        let pop = APP.findClass(data, 'pop');
        let pop_close = APP.findClass(data, 'pop_close');
        let btn_text = APP.findClass(data, 'btn_text');
        if(pop && !pop_close && btn_text){
             await this.checkPop_1();
        }
        // APP.ocrDataFindText(data,'授权登录');


        // if(pop_close){
        //     await APP.clickRegion(this.androidBot, data[pop_close - 1].region);
        // }
        // await this.pop_sys_oneBtn(data);
        if(this.done){
            await APP.sleep();
        }
        return this.done;
    }
}

module.exports = index;